package edu.Ding.A0426;

/* 封装： 对用户隐藏其属性或行为，对外提供一个公开的接口，
 *  让用户间接访问，以提高程序的可维护性以及安全性
 *  属性的封装： private对属性的权限做限制，接着对外提供
 *          一个公开的访问方法  getter/setter
 *  行为(方法)的封装：将实现逻辑对外进行隐藏，外界只知道
 *          当前方法的名字、参数列表、返回值。
 */

/*定义类Dog，对其属性名字、毛色、品种、体重进行封装，
 *尝试使用get以及set进行赋值以及取值。
 */

class Dog{

    private String name;
    private String color;
    private String variety;
    private String weight;

    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name = name;
    }
    public String getColor(){
        return color;
    }
    public void setColor(String color){
        this.color = color;
    }
    public String getVariety(){
        return variety;
    }
    public void setVariety(String variety){
        this.variety = variety;
    }
    public String getWeight() {
        return weight;
    }
    public void setWeight(String weight) {
        this.weight = weight;
    }

    public void print(){
        System.out.println("名字："+name+"，颜色："+color+"，品种："+variety+"，重量："+weight+"。");
    }
    public void print2(){
        System.out.println("name："+name+"，color："+color+"，variety："+variety+"，weight："+weight+"。");
    }

    public Dog(String name, String color, String variety, String weight) {
        this.name = name;
        this.color = color;
        this.variety = variety;
        this.weight = weight;
    }
}

public class Demo1 {
    public static void main(String[] args) {
        Dog dog = new Dog("贝贝","黑色","德牧","40KG");
        dog.print();

        String name = dog.getName();
        String color = dog.getColor();
        String variety = dog.getVariety();
        String weight = dog.getWeight();
        System.out.println("名字："+name+"，颜色："+color+"，品种："+variety+"， 重量："+weight+"。");

        dog.setName("beibei");
        dog.setColor("black");
        dog.setVariety("German Shepherd Dog");
        dog.print2();

    }
}
